<?php
declare (strict_types=1);

namespace app\admin\controller;

use think\App;
use think\facade\View;
use think\response\Json;

class CurriculumCate extends Base
{

    protected string $pk = 'id';

    protected string $validate = 'CurriculumCate';

    protected string $model = '\app\common\model\CurriculumCate';

    protected int $writeLog = 2;


    public function index(): string
    {
        View::assign('list', $this->model::getAll());
        return View::fetch();
    }

    public function edit($id = '', $pid = '', $tpl = 'curriculum_cate/edit'): string
    {
        $p_title = '';
        if ($pid) {
            $p_title = $this->model::where('id', $pid)->value('title');
        }

        View::assign('p_title', $p_title);
        View::assign('form', ['title' => '图标', 'field' => 'icon', 'value' => 1]);
        return parent::edit($id, $tpl);
    }

    public function save($param = [], $model = false): Json
    {
        $param = $this->request->post();
//        if(isset( parse_url($param['icon'])['path']))
//        {
//            $param['icon'] = parse_url($param['icon'])['path'];
//        }

        return parent::save($param, $model); // TODO: Change the autogenerated stub
    }

    public function getCate(): \think\response\Json
    {
        $id = $this->request->param('id', 0);
        return json($this->model::getCate($id));
    }

}
